﻿###########################
#
#  Purpose: Background process to make sure windows has a process maximized or any other setting.
#  Created By: Chris Towles
#  When: 11/12/2010
#  Version: 1.0
#  Change List
#
###########################

function VMwareView-FixWindowSize
{
	$procList = $null
	$RemoteList = $null				
	
	$procList = Get-Process "wswc" -ErrorAction SilentlyContinue
	
	if($procList -ne $null)
	{
		Foreach($proc in $procList){
			$RemoteList = Get-Process "vmware-remotemks" -ErrorAction SilentlyContinue
			if($RemoteList -ne $null){		
				$app::ShowWindow($proc.MainWindowHandle, 3)
			}
			else {
				$app::ShowWindow($proc.MainWindowHandle, 9)
			}
			#shows the sizes 9- restores window , 3 is maximize
			#http://msdn.microsoft.com/en-us/library/ms633548(VS.85).aspx   
		}
	}	
}


$signature = @"  
        [DllImport("user32.dll")]  
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
"@

$app = Add-Type -MemberDefinition $signature  -Name Win32Window -ReferencedAssemblies System.Windows.Forms -Using System.Windows.Forms -Namespace test -PassThru 

while($true) {
	VMwareView-FixWindowSize
	sleep 5 
}
	
	